package action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_company_info.EntityBeanOc_Company_Info;
import entitybean.oc_evaluate.EntityBeanOc_Evaluate;
import entitybean.oc_friendly_link.EntityBeanOc_Friend_Link;
import entitybean.oc_if_evaluate.EntityBeanOc_If_Evaluate;
import entitybean.oc_news.EntityBeanOc_News;
import entitybean.oc_study.EntityBeanOc_Study;
import entitybean.oc_user_name.EntityBeanOc_User_Name;
import form.EvaluateIfForm;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.Convert;
import tools.Pager;
import tools.Result;

public class Action_Show extends DispatchAction{
	private Service_Search service_search;
	private Service_Public service_public;
	private Service_Admin service_admin;
	
	public Service_Admin getService_admin() {
		return service_admin;
	}
	public void setService_admin(Service_Admin serviceAdmin) {
		service_admin = serviceAdmin;
	}
	public Service_Search getService_search() {
		return service_search;
	}
	public void setService_search(Service_Search serviceSearch) {
		service_search = serviceSearch;
	}
	public Service_Public getService_public() {
		return service_public;
	}
	public void setService_public(Service_Public servicePublic) {
		service_public = servicePublic;
	}
	
	public ActionForward show_news_detail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		String id=request.getParameter("id");
		EntityBeanOc_News e=this.service_admin.Find_Oc_News_By_Id(id);
		Convert convert=new Convert();
		//System.out.println(convert.ConvertClobToString(e.getNews_clob()));
		e.setNews_clob_string(convert.ConvertClobToString(e.getNews_clob()));
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}
	
	
	public ActionForward show_friend_link(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{

		List<EntityBeanOc_Friend_Link>list_friend_link=this.service_admin.Find_Oc_Friend_Link();

		List<EntityBeanOc_Study> list_evaluate=this.service_admin.Find_EntityBeanOc_Study(9);
		List<EntityBeanOc_Company_Info>list_company_info=this.service_admin.Find_EntityBeanOc_Company_Info();
		request.setAttribute("list_friend_link",list_friend_link );
		request.setAttribute("list_evaluate",list_evaluate );
		request.setAttribute("list_company_info",list_company_info );
		
		return mapping.findForward("success");
	}
	public ActionForward show_news_link(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		List<EntityBeanOc_News>list_news=this.service_admin.Find_Oc_News(8);		
		request.setAttribute("list_news",list_news );
		return mapping.findForward("success");
	}
	public ActionForward show_adv_2(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{

		return mapping.findForward("success");
	}
	public ActionForward show_adv(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{

		return mapping.findForward("success");
	}
	public ActionForward show_news_list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{    
		Pager pager=new Pager(10); 
		String tableName="EntityBeanOc_News" ; 
		pager.setPageName(tableName); 
		String conditionString=" del='OFF' order by id desc " ; 
		pager.setConString(conditionString); 
		int pageNum=1; 
		String num=request.getParameter("pageNum");
		if(!"".equals(num)&& num!=null){
		  pageNum=Integer.valueOf(num);
		}
		pager.setCurrentPage(pageNum); 
		Result result = service_admin.listProduct(pager); 
		pager = result.getPager(); 
		request.setAttribute("PlaceView" , result); 

		return mapping.findForward("success");
	}
	public ActionForward show_evaluate_list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		EntityBeanOc_User_Name e = new EntityBeanOc_User_Name();
		e=(EntityBeanOc_User_Name)request.getSession().getAttribute("Ocean_User");
		if(e==null)
		{
			return mapping.findForward("error");
		}
        List<EntityBeanOc_If_Evaluate> t=this.service_search.Find_EntityBeanOc_If_Evaluate("1", e.getId());
        List<EntityBeanOc_If_Evaluate> s=this.service_search.Find_EntityBeanOc_If_Evaluate_Del("0", e.getId());
        if(t.size()>0){
        	Pager pager=new Pager(10); 
        	String tableName="EntityBeanOc_Evaluate" ; 
        	pager.setPageName(tableName); 
        	String conditionString=" del='OFF' order by id desc" ;
        	pager.setConString(conditionString); 
        	int pageNum=1; 
    		String num=request.getParameter("pageNum");
    		if(!"".equals(num)&& num!=null){
    		  pageNum=Integer.valueOf(num);
    		}
        	pager.setCurrentPage(pageNum); 
        	Result result = service_admin.listProduct(pager); 
        	pager = result.getPager(); 
        	request.setAttribute("PlaceView" , result);
        	return mapping.findForward("success");
        }else if(s.size()>0){
		   return mapping.findForward("audit");
        }else{
           return mapping.findForward("application");
        }
	}
	public ActionForward show_study_list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		Pager pager=new Pager(20); 
		String tableName="EntityBeanOc_Study" ;
		pager.setPageName(tableName); 
		String conditionString=" del='OFF' order by id desc " ; 
		pager.setConString(conditionString); 
		int pageNum=1; 
		String num=request.getParameter("pageNum");
		if(!"".equals(num)&& num!=null){
		  pageNum=Integer.valueOf(num);
		}
		pager.setCurrentPage(pageNum); 
		Result result = service_admin.listProduct(pager); 

		pager = result.getPager(); 
		request.setAttribute("PlaceView" , result); 
		
		return mapping.findForward("success");
	}
	public ActionForward show_study_detail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		String id = request.getParameter("id");
		
		EntityBeanOc_Study e = this.service_admin.Find_Oc_Study_By_Id(id);
		Convert convert=new Convert();
		e.setNews_clob_string(convert.ConvertClobToString(e.getNews_clob()));
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}
	
	public ActionForward show_evaluate_list_all(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
    	Pager pager=new Pager(10); 
    	String tableName="EntityBeanOc_Evaluate" ; 
    	pager.setPageName(tableName); 
    	String conditionString=" del='OFF' " ; 
    	pager.setConString(conditionString); 
    	int pageNum=1; 
    	pageNum=Integer.valueOf(request.getParameter("pageNum"));
    	pager.setCurrentPage(pageNum); 
    	Result result = service_admin.listProduct(pager); 
    	pager = result.getPager(); 
    	request.setAttribute("PlaceView" , result);
    	return mapping.findForward("success");
	}
	public ActionForward admin_insert_if_evaluate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateIfForm goodForm = (EvaluateIfForm) form;
		String oc_evaluate = goodForm.getOc_evaluate();
		String unit = goodForm.getUnit();
		String position = goodForm.getPosition();
		String phone = goodForm.getPhone();
		EntityBeanOc_User_Name e = new EntityBeanOc_User_Name();
		e=(EntityBeanOc_User_Name)request.getSession().getAttribute("Ocean_User");
		if(e==null)
		{
			System.out.println("会话变量丢失");
			return mapping.findForward("error");
		}
		EntityBeanOc_If_Evaluate link = new EntityBeanOc_If_Evaluate();
		link.setOc_evaluate(oc_evaluate);
        link.setOc_user_name_id(e.getId());
        link.setSubmit_time(new Date());
        link.setPass_time(new Date());
		link.setDel("0");
		link.setUnit(unit);
		link.setPosition(position);
		link.setPhone(phone);
		link.setName(e.getUsername());
		Integer i = 0;
		EntityBeanL_Sequence entity = new EntityBeanL_Sequence();
		entity = this.service_public
				.Find_L_Sequence_By_seq_Name("SEQ_OC_BOAT_ICE");
		i = entity.getSeq_Value() + 1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_search.Insert_Oc_Evaluate(link);
		return mapping.findForward("success");
	}
	public ActionForward admin_show_view_ealuate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateIfForm boatIceForm = (EvaluateIfForm) form;
		String id = boatIceForm.getId();
		EntityBeanOc_If_Evaluate ifevaluate=this.service_search.Find_EntityBeanOc_If_Evaluate(Integer.valueOf(id));
		request.setAttribute("ifevaluate", ifevaluate);
		return mapping.findForward("success");
	}
	public ActionForward admin_show_ealuate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		EvaluateIfForm boatIceForm = (EvaluateIfForm) form;
		String id = boatIceForm.getId();
		EntityBeanOc_Evaluate evaluate=this.service_admin.Find_EntityBeanOc_Evaluate(Integer.valueOf(id));
		Convert convert=new Convert();
		evaluate.setNews_clob_string(convert.ConvertClobToString(evaluate.getNews_clob()));
		request.setAttribute("PlaceView", evaluate);
		return mapping.findForward("success");
	}
}
